package com.tinycloud.miracll.product.api;

import com.tinycloud.common.core.web.controller.BaseController;
import com.tinycloud.common.log.annotation.Log;
import com.tinycloud.common.log.enums.BusinessType;
import com.tinycloud.miracll.product.job.SCADATask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * 产品成本Controller
 * 
 * @author tiny
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/api/productScada")
public class ProductScadaAPI extends BaseController
{
    @Autowired
    private SCADATask scadaTask ;


    /**
     * 生成产成品成本基础数据
     */

    @Log(title = "偏差分析", businessType = BusinessType.INSERT)
    @GetMapping("/getProductData")
    @ResponseBody
    public String getProductData()  {
        String result = "success";
        try {
            scadaTask.getProductData();
        } catch (Exception e) {
            result = "error";
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 定时清洗scada报警数据
     */

    @Log(title = "scada报警清洗", businessType = BusinessType.INSERT)
    @GetMapping("/cleanScadaAlarmData")
    @ResponseBody
    public String cleanScadaAlarmData()  {
        String result = "success";
        try {
            scadaTask.cleanScadaAlarmData();
        } catch (Exception e) {
            result = "error";
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 定时同步ERP偏差数据至scada
     */

    @Log(title = "ERP偏差数据同步", businessType = BusinessType.INSERT)
    @GetMapping("/productKeyProcessConfERP2Scada")
    @ResponseBody
    public String productKeyProcessConfERP2Scada()  {
        String result = "success";
        try {
            scadaTask.productKeyProcessConfERP2Scada();
        } catch (Exception e) {
            result = "error";
            e.printStackTrace();
        }
        return  result;
    }

    /**
     * 定时清洗
     */

    @Log(title = "自动助剂称量数据清洗", businessType = BusinessType.INSERT)
    @GetMapping("/auxiSysWeightDadaClean")
    @ResponseBody
    public String auxiSysWeightDadaClean()  {
        String result = "success";
        try {
            scadaTask.auxiSysWeightDadaClean();
        } catch (Exception e) {
            result = "error";
            e.printStackTrace();
        }
        return  result;
    }

}
